<!-- Whizzylink.php 
PARAMETERS are optional: 
 d=start directory  
   default is the root directory 
 x=list of file extensions to consider, separated by '|' 
   default is htm|html|txt|doc|xls|ppt|pdf|cfm (NB asp|php|shtml Not included in default)
 b=path to button images
   default is /btn
e.g. whizzylink.php?d=publicpages&x=html|pdf|php
-->
<html>
<head>
<title>Whizzylink link browse v4</title>
<style>
body {font:85% sans-serif;}
</style>
<script type="text/javascript">
function WantThis(url) {
 window.opener.document.getElementById('lf_url').value = url;
 window.close();
}
</script>
<META NAME="ROBOTS" CONTENT="NOINDEX,NOFOLLOW">
</head>
<body>
<div id="files" >
Click a name below to select.<br>
<?php
$butpath = $_REQUEST['b'] ? $_REQUEST['b'] : '/btn';
$extensions = $_REQUEST['x'] ? '/\.(' . $_REQUEST['x'] .')$/i' : '/\.(htm|html|txt|doc|xls|ppt|pdf|cfm)$/i';
$docpath = trim($_REQUEST['d'],"/");
$d = $_SERVER['DOCUMENT_ROOT'] . '/' . $docpath;
$dir = opendir($d);
while ($file = readdir($dir)){
  $files[] = $file;
}
closedir($dir);
natcasesort($files); //see function insensitive($a, $b)
foreach ($files as $filename) {
  $filepath = "$d/$filename";
  if (@is_dir($filepath)) { //it's a directory
    if ($filename == '.'){ //current directory
      $dlist .= "<img src='".$butpath."/dir.gif'> $docpath ";
    } else if ($filename == '..') { //parent directory
      if($docpath) { //we're in a sub directory - no Up from root
        $updir = substr($docpath,0,strrpos($docpath,'/'));
        $dlist .= "<img src='".$butpath."/back.gif'><a href='$self?d=$updir'>Up</a>/<br>";
       }
    } else {
      //$docpath = str_replace($_SERVER['DOCUMENT_ROOT'], "", $d);//NEEDED?
      $dlist .= "<div style='float:left;width:20em'><img src='".$butpath."/dir.gif'><a href='$self?d=$docpath/$filename'>$filename</a></div>"; 
    }
  } else if (preg_match($extensions,$filename) || strpos($filename,'.') === false) { //hide forbidden extensions
      $flist .= "<div style='float:left;width:20em'><a href='#' onclick='WantThis(\"$docpath/$filename\")'>$filename</a></div>"; //it's a potential link
  }
}
echo $dlist . $flist;

?>
</div>
</body>
</html>